import request from 'axios';

import { LOAD_DIR, EXPAND_DIR, COLLAPSE_DIR, arrayToProps } from '../reducers/directory.js';

/**
 * 读取目录信息
 * @return {Object}
 */
export function loadDirectory() {
    return {
        type: LOAD_DIR,
        payload: {
            promise: request.get('/fs/dir')
                .then(response => response.data)
        }
    };
}

/**
 * 展开目录
 * @param  {number} path
 * @return {Object}
 */
export function expandDirectory(...path) {
    return {
        type: EXPAND_DIR,
        payload: arrayToProps(path)
    };
}

/**
 * 收起目录
 * @param  {number} path
 * @return {Object}
 */
export function collapseDirectory(...path) {
    return {
        type: COLLAPSE_DIR,
        payload: path
    };
}